
#ifndef __PERSISTENT_FORWARD_CHANNEL_H
#define __PERSISTENT_FORWARD_CHANNEL_H

#include "../aprtools/APRBucketBrigade.h"
#include "../aprtools/APRFuture.h"
#include "ForwardServer.h"
#include "SSHChannel.h"

/** Class encapsulating a persistent forwarding service over the SSH
 * connection. */
class PersistentForwardChannel : public SSHChannel
{
   public:
      PersistentForwardChannel(SSHClient &itclient, int inothreads, int ilocalportno, const char *ilocalhostname,
         int iremoteportno, const char *iremotehostname);
      PersistentForwardChannel(SSHClient &itclient, int inothreads, int ilocalportstart, int ilocalportend, const char *ilocalhostname,
         int iremoteportno, const char *iremotehostname);
      virtual ~PersistentForwardChannel();
      /** Check whether the forwarding service is active. */
      int isUp()
      {
         if ((fwdserver) && (tchannel))
            return fwdserver->isListening();
         else
            return 0;
      }
      const char *getRealRemoteHost() const { return remotehostname; }
      const int getRealRemotePort() const { return remoteport; }
      const int getLocalListenPort() const { return localport; }
   protected:
      LIBSSH2_CHANNEL *getPersistentForwardingChannel(const char *ilocalhost, int ilocalport, const char *iremotehost, int iremoteport);
      int localport;
      char *localhostname;
      int remoteport;
      char *remotehostname;
      ForwardServer *fwdserver;
      LIBSSH2_CHANNEL *tchannel;
};

#endif
